#!usr/bin/env python3
import pyautogui as pg
import time
# 需要用sys.argv[1:]参数
import sys
import getopt


def clickCenter(center, clicks=1, button='left', interval=0.0):
    pg.click(phoneTopLeftPosition[0] + center[0],
             phoneTopLeftPosition[1] + center[1],
             clicks=clicks,
             button=button,
             interval=interval)


def moveCenter(center):
    pg.moveTo(phoneTopLeftPosition[0] + center[0],
              phoneTopLeftPosition[1] + center[1])


def imgCenter(imgName=None, modeException=True):
    if imgName == None:
        raise Exception('imgCenterClickLackFileName')

    center = pg.locateCenterOnScreen(imgName)
    if center != None:
        return center
    else:
        if modeException == True:
            raise Exception('imgCenterClickNoneCenter')
        else:
            return None


if __name__ == '__main__':

    print(sys.argv)

    try:
        # 三种参数,help(h),username(u),password(p)。第一个不需要值，另外两个需要值
        opts, args = getopt.getopt(sys.argv[1:], "x:y:", ["x=", "y="])
        x = 0
        y = 0
        # 就是处理每个元组
        for k, v in opts:
            if k in ("-x", "--x"):
                x = v
            elif k in ("-y", "--y"):
                y = v
    # 报错是getopt.GetoptError
    except getopt.GetoptError:
        print('[getopt.GetoptError]')
        sys.exit()

    phoneTopLeftPosition = (int(x), int(y))
    # width x height
    phoneSize = (559, 990)
    phoneButtomRightPosition = (phoneTopLeftPosition[0] + phoneSize[0],
                                phoneTopLeftPosition[1] + phoneSize[1])

    region = (phoneTopLeftPosition[0], phoneTopLeftPosition[1], phoneSize[0],
              phoneSize[1])

    pg.PAUSE = 0.5

    posList = [(281, 605), (100, 950), (500, 50), (300, 640)]
    timeList = [2, 50, 5, 10]

    while True:
        for i in range(0, len(posList)):
            clickCenter(posList[i])
            time.sleep(timeList[i])